package com.example.s.Activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.s.R;
import com.example.s.adapter.InnerHolder;
import com.example.s.adapter.MyRecyclerViewAdapter;
import com.example.s.bean.MessageCommon;

import java.util.ArrayList;
import java.util.List;

public class MessageCommonActivity extends BaseActivity {
    private ImageView back;
    private TextView title;
    private ImageView titleIcon;
    private RecyclerView rv;
    private List<MessageCommon> messageCommonList = new ArrayList<>();
    private MyRecyclerViewAdapter<MessageCommon> mCommonAdapter;

    private void initView() {

        back = (ImageView) findViewById(R.id.back);
        title = (TextView) findViewById(R.id.title);
        titleIcon = (ImageView) findViewById(R.id.titleIcon);
        rv = (RecyclerView) findViewById(R.id.rv);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_message_child_common);
        initView();
        rv.setLayoutManager(new LinearLayoutManager(this));
        Intent intent = getIntent();
        int message_type = intent.getIntExtra("message_type", 1);
        if (message_type == 1) {
            title.setText("新增关注");
            titleIcon.setBackgroundResource(R.mipmap.message_attention);
            setAttentionData();
            setAttentionAdapter();
        } else if (message_type == 2) {
            title.setText("赞和收藏");
            titleIcon.setBackgroundResource(R.mipmap.message_praise);
            setPriseData();
            setPriseAdapter();
        } else if (message_type == 3) {
            title.setText("评论和@");
            titleIcon.setBackgroundResource(R.mipmap.message_comment);
            setCommentData();
            setCommentAdapter();
        }
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setResult(201);
                finish();
            }
        });


    }



    private void setAttentionData() {
        messageCommonList.clear();
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",true));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",true));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",true));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",true));
    }

    private void setAttentionAdapter() {

        rv.setAdapter(mCommonAdapter = new MyRecyclerViewAdapter<MessageCommon>(messageCommonList, R.layout.rv_message_common_item) {
            @Override
            public void handleData(InnerHolder holder, MessageCommon item) {
                holder.setSrcResource(R.id.headphoto, R.drawable.ic_launcher_background);  //修改头像
                holder.setText(R.id.name, item.getmName());
                holder.setText(R.id.content, MessageCommon.ATTENTIONSTRING);
                holder.setText(R.id.time, item.getmTime());
                TextView attention = holder.getView(R.id.attention);
                attention.setBackgroundResource(R.drawable.message_attentiont);
                attention.setText("回关");
                attention.setTextColor(Color.parseColor("#FFFC4545"));
                attention.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if("回关".contentEquals(attention.getText())){
                            attention.setTextColor(Color.WHITE);
                            attention.setText("已关注");
                            attention.setBackgroundResource(R.drawable.message_attention_select);
                        }else {
                            attention.setTextColor(Color.parseColor("#FFFC4545"));
                            attention.setText("回关");
                            attention.setBackgroundResource(R.drawable.message_attentiont);
                        }
                    }
                });
                holder.setVisibility(R.id.workIconContainer, false);
                holder.getView(R.id.comment).setVisibility(View.GONE);
            }
        });
    }


    private void setPriseData() {
        messageCommonList.clear();

        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",""));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",""));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",""));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",""));
    }

    private void setPriseAdapter() {
        rv.setAdapter(mCommonAdapter = new MyRecyclerViewAdapter<MessageCommon>(messageCommonList, R.layout.rv_message_common_item) {
            @Override
            public void handleData(InnerHolder holder, MessageCommon item) {
                holder.setSrcResource(R.id.headphoto, R.drawable.ic_launcher_background);  //修改头像
                holder.setText(R.id.name, item.getmName());
                holder.setText(R.id.content, MessageCommon.PRISE_WORK_STRING);
                holder.setText(R.id.time, item.getmTime());
                holder.setVisibility(R.id.attention, false);
                holder.setVisibility(R.id.workIconContainer, true);
                holder.setImageResource(R.id.workIcon,R.mipmap.home_page_contact_icon);  //修改作品icon
                holder.getView(R.id.comment).setVisibility(View.GONE);
            }
        });
    }


    private void setCommentData() {
        messageCommonList.clear();

        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",false,"太美了"));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",false,"太美了"));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",false,"太美了"));
        messageCommonList.add(new MessageCommon("","杨叶文","2小时之前",false,"太美了"));
    }



    private void setCommentAdapter() {
        rv.setAdapter(mCommonAdapter = new MyRecyclerViewAdapter<MessageCommon>(messageCommonList, R.layout.rv_message_common_item) {
            @Override
            public void handleData(InnerHolder holder, MessageCommon item) {
                holder.setSrcResource(R.id.headphoto, R.drawable.ic_launcher_background);  //修改头像
                holder.setText(R.id.name, item.getmName());
                holder.setText(R.id.content, MessageCommon.COMMENT_STRING);
                holder.setText(R.id.time, item.getmTime());
                holder.setVisibility(R.id.attention, false);
                holder.setVisibility(R.id.workIconContainer, true);
                holder.setImageResource(R.id.workIcon,R.mipmap.home_page_contact_icon);  //修改作品icon
                Log.d(TAG, "handleData: "+item.getmCommentContent());
                holder.setText(R.id.comment, item.getmCommentContent());
            }
        });
    }


}
